<?php
/**
 * @package mikrokosmos
 * mk script created on 4-giu-2005
 * jaco_at_pixeldump_dot_org
 */

if(!class_exists("MKTagHeader")){ class MKTagHeader {}}

/**
 * DefineFontInfo/2 class
 */
class MKFontInfo {
/*
Header RECORDHEADER Tag type = 62.
FontID UI16 Font ID this information is for.
FontNameLen UI8 Length of font name.
FontName UI8[FontNameLen] Name of the font.
FontFlagsReserved UB[2] Reserved bit fields.
FontFlagsSmallText UB[1] SWF 7 or later:
Font is small. Character glyphs
are aligned on pixel boundaries
for dynamic and input text.
FontFlagsShiftJIS UB[1] Always 0.
FontFlagsANSI UB[1] Always 0.
FontFlagsItalic UB[1] Font is italic.
FontFlagsBold UB[1] Font is bold.
FontFlagsWideCodes UB[1] Always 1.
LanguageCode LANGCODE Language ID.
CodeTable UI16[nGlyphs] Glyph to code table in UCS-2,
sorted in ascending order.
*/
	function MKFontInfo($tagData = "", $fontID = 1){

	}
}

class MKStaticText extends MKTagHeader {

	var $tagData = "";

	// alias of itemID
	// var $characterID;		//  UI16 ID for this text character.

	var $textBounds;			//  RECT Bounds of the text.
	var $textMatrix;		    //  MATRIX Transformation matrix.
	var $glyphBits;				//  UI8 Bits in each glyph index.
	var $advanceBits;			//  UI8 Bits in each advance value.
	var $textRecords = array(); // TEXTRECORD[zero or more] Text records.
	var $endOfRecordsFlag = 0;	// UI8 Must be 0.

	function MKStaticText($tagData = "", $characterID = 1){
		$this->itemID = $characterID;
		$this->tagData = $tagData;
		$this->get_defineText_data();
	}

	function set_defineText_data($dtd = array()){

		if(!count($dtd)) $dtd = $this->fetch_assoc();

		$this->tagData = write_defineText_data($dtd);

		return $this->tagData();
	}

	function get_defineText_data($dtd = array()){

		if(!count($dtd)) $dtd = read_defineText_data($this->tagData);

		$this->itemID = $dtd["itemID"];

		$this->textBounds = new MKRect();
		$this->textBounds->get_rect_data($dtd["textBounds"]);

		$this->textMatrix = new MKMatrix();
		$this->textMatrix->get_matrix_data($dtd["textMatrix"]);

		$this->glyphBits = $dtd["glyphBits"];
		$this->advanceBits = $dtd["advanceBits"];
		$dtd["textRecords"] = array();

		foreach($dtd["textRecords"] as $trd)
			$dtd["textRecords"][] = new MKTextRecord("", $trd);
	}


	function fetch_assoc(){

		$dtd = array();
		$dtd["itemID"] 	  	= $this->itemID;
		$dtd["characterID"]	= $this->itemID;

		$dtd["textBounds"] = $this->textBounds->fetch_assoc();
		$dtd["textMatrix"] = $this->textMatrix->fetch_assoc();
		$dtd["glyphBits"] = $this->glyphBits;
		$dtd["advanceBits"] = $this->advanceBits;
		$dtd["textRecords"] = array();

		foreach($this->textRecords as $tr)
			$dtd["textRecords"][] = $tr->fetch_assoc();

		return $dtd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "staticText"){

		$dtd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "characterID=\"" . $dtd["itemID"] ."\" >";
		$pfx = get_xml_indent_row(++$tabLevel);

		$xmlStr .= $this->textBounds->fetch_xml(false, $tabLevel, "textBounds");
		$xmlStr .= $this->textMatrix->fetch_xml(false, $tabLevel, "textMatrix");

		$xmlStr .= "<hexData>" .hex_dump($this->tagData, true) ."</hexData>";

		/* TODO: implement textRecords array */
		$pfx = get_xml_indent_row(--$tabLevel);
		$xmlStr .= $pfx ."</" .$nodeName .">";

		return $xmlStr;
	}
}


/**
 * class wrapper for
 * dynamic/input text
 *
 */
class MKTextField extends MKTagHeader {

	var $tagData = "";

	//alias of itemID
	//var $characterID = 2;		// UI16 ID for this dynamic text character
	var $bounds;				// RECT Rectangle that completely
								// encloses the text field
	var $hasText = 0;			// UB[1] 0 = text field has no default text
								// 1 = text field initially displays the
								// string specified by InitialText
	var $wordWrap = 0;			// UB[1] 0 = text will not wrap and will
								// scroll sideways
								// 1 = text will wrap automatically
								// when the end of line is reached
	var $multiline = 0;			// UB[1] 0 = text field is one line only
								// 1 = text field is multi-line and will
								// scroll automatically
	var $password = 0;			// UB[1] 0 = characters are displayed as typed
								// 1 = all characters are displayed as an asterisk
	var $readOnly = 0;			// UB[1] 0 = text editing is enabled
								// 1 = text editing is disabled
	var $hasTextColor = 1;		// UB[1] 0 = use default color
								// 1 = use specified color (TextColor)
	var $hasMaxLength = 0;		// UB[1] 0 = length of text is unlimited
								// 1 = maximum length of string is
								// specified by MaxLength
	var $hasFont = 0;			// UB[1] 0 = use default font
								// 1 = use specified font (FontID)
								// and height (FontHeight)
	var $hasFontClass = 0;		// UB[1] 1 = font class to be loaded
	var $autoSize = 0;			// UB[1] 0 = fixed size
								// 1 = sizes to content (SWF 6 or later only)
	var $hasLayout = 1;			// UB[1] Layout information provided
	var $noSelect = 0;			// UB[1] Enables or disables interactive
								// text selection
	var $border = 0;			// UB[1] Causes a border to be drawn
								// around the text field
	var $wasStatic = 0;			// UB[1] authored as static/textfield
	var $html = 0;				// UB[1] 0 = plaintext content
								// 1 = HTML content (see below)
	var $useOutlines = 0;		// UB[1] 0 = use device font
								// 1 = use glyph font
	var $fontID = 1;			// If HasFont UI16 ID of font to use

	var $fontClassName = "";    // name of the font class

	var $fontHeight = 240;		// If HasFont UI16 Height of font in twips
	var $textColor;				// If HasTextColor RGBA Color of text
	var $maxLength;				// If HasMaxLength UI16 Text is restricted to this length
	var $align = 0;				// If HasLayout UI8 0 = Left
								// 1 = Right
								// 2 = Center
								// 3 = Justify
	var $leftMargin = 0;		// If HasLayout UI16 Left margin in twips
	var $rightMargin = 0;		// If HasLayout UI16 Right margin in twips
	var $indent = 0;			// If HasLayout UI16 Indent in twips
	var $leading = 40;			// If HasLayout UI16 Leading in twips (vertical
								// distance between bottom of
								// descender of one line and top of
								// ascender of the next)
	var $variableName = "";		// STRING Name of the variable where the
								// contents of the text field are
								// stored. May be qualified with
								// dot syntax or slash syntax for
								// non-global variables.
	var $initialText = "";		// If HasText STRING Text that is initially displayed

	var $x = -40;				// initial x in twips
	var $y = -40;				// initial y in twips
	var $width = 2000;			// default width in twips
	var $height = 640;			// default height in twips

	var $po;

	// the constructor
	function MKTextField($tagData = "", $itemID = 2, $fontID = 1){

		$this->itemID = $itemID;
		$this->set_fontID($fontID);

		$this->po = new MKPlaceObject2("", $itemID, $itemID);
		//$this->po->set_characterID($this->itemID);

		if(strlen($tagData)){
			parent::MKTagHeader(substr($tagData, 0, 10));
			$this->tagData = $tagData;
			$this->get_textField_data();
			return;
		}

		$this->bounds = new MKRect("",
									$this->x, $this->x + $this->width,
									$this->y, $this->y + $this->height);
		$this->textColor = new MKColor();
		$this->textColor->set_color(get_color_array("#000000"));
		$this->textColor->set_alpha(0xff);
		//$this->update_bounds();
	}

	// these are flag setter getter, note that
	// in some cases there are function alias to
	// reach code more readable
	// e.g. set_text is more intuitive than set_initialText

	function set_itemID($itemID){
		$this->itemID = $itemID;
		$this->po->set_characterID($this->itemID);
	}


	//
	function set_characterID($characterID){
		$this->itemID = $characterID;
		$this->po->set_characterID($this->itemID);
	}
	function get_characterID(){ return $this->itemID; }

	function set_bounds($boundsAr) {
		$this->bounds = new MKRect("",
									$boundsAr["xmin"], $boundsAr["xmax"],
									$boundsAr["ymin"], $boundsAr["ymax"]);
	}
	function get_bounds() { return $this->bounds->fetch_assoc(); }

	//
	function update_bounds(){
		$this->bounds->set_xmin($this->x);
		$this->bounds->set_xmax($this->x + $this->width);
		$this->bounds->set_ymin($this->y);
		$this->bounds->set_ymax($this->y + $this->height);
	}

	function set_wordWrap($wordWrap = 1) {$this->wordWrap = $wordWrap; }
	function get_wordWrap() {return $this->wordWrap; }

	function set_multiline($multiline = 1) {$this->multiline = $multiline; }
	function get_multiline() { return $this->multiline; }

	function set_password($password) {$this->password = $password; }
	function get_password() { return $this->password; }

	//
	function set_readOnly($readOnly = 1) {
		$this->readOnly = $readOnly;
		if($readOnly == INPUT_TEXT)	$this->noSelect = 0;
	}
	function get_readOnly() { return $this->readOnly; }

	function set_Type($readOnly = 1){ $this->set_readOnly($readOnly); }
	function get_Type(){ return $this->set_readOnly; }

	//
	function set_autoSize($autoSize = 1) { $this->autoSize = $autoSize; }
	function get_autoSize() { return $this->autoSize; }

	function set_noSelect($noSelect){ $this->noSelect = $noSelect; }
	function get_noSelect() { return $this->noSelect; }

	function set_selectable($selectable = 1){
		$noSelect = $selectable ? 0 : 1;
		$this->set_noSelect($noSelect);
	}
	function get_selectable() { return $this->noSelect; }

	function set_border($border = 1){ $this->border = $border; }
	function get_border() { return $this->border; }

	function set_wasStatic($wasStatic = 1){ $this->wasStatic = $wasStatic; }
	function get_wasStatic() { return $this->wasStatic; }

	function set_html($html = 1) { $this->html = $html; }
	function get_html() { return $this->html; }

	function set_useOutlines($useOutlines = 1) { $this->useOutlines = $useOutlines; }
	function get_useOutlines() { return $this->useOutlines; }

	function set_fontID($fontID = 1) {
		$this->fontID = $fontID;
		$this->hasFont = $fontID ? 1 : 0;
	}
	function get_fontID() { return $this->fontID; }

	function set_fontHeight($fontHeight){
		$this->fontHeight = nmb2Twip($fontHeight);
		$this->hasFont = 1;
	}
	function get_fontHeight() { return twip2nmb($this->fontHeight); }

	function set_hasFont($hasFont = 0) { $this->hasFont = $hasFont; }
	function get_hasFont() { return $this->hasFont; }

	function set_textColor($cAr){
		$this->textColor = new MKColor();
		if(is_array($cAr))
			$this->textColor->set_color($cAr);
		else {
			$this->textColor->set_color(get_color_array($cAr));
			if(strlen($cAr) == 7) $this->textColor->set_alpha(0xff);
		}
		$this->hasTextColor = 1;
	}
	function get_textColor() { return $this->textColor->get_color(); }

	function set_hasTextColor($hasTextColor) { $this->hasTextColor = $hasTextColor; }
	function get_hasTextColor() { return $this->hasTextColor; }

	function set_maxLength($maxLength) {
		$this->maxLength = $maxLength;
		$this->hasMaxLength = 1;
	}
	function get_maxLength() { return $this->maxLength; }

	function set_hasMaxLength($hasMaxLength){ $this->hasMaxLength = $hasMaxLength; }
	function get_hasMaxLength() { return $this->hasMaxLength; }

	function set_hasLayout($hasLayout) { $this->hasLayout = $hasLayout; }
	function get_hasLayout() { return  $this->hasLayout; }

	function set_align($align){
		$this->align = $align;
		$this->hasLayout = 1;
	}
	function get_align() { return $this->align; }

	function set_leftMargin($leftMargin) {
		$this->leftMargin = $leftMargin;
		$this->hasLayout = 1;
	}
	function get_leftMargin() { return $this->leftMargin; }

	function set_rightMargin($rightMargin) {
		$this->rightMargin = nmb2Twip($rightMargin);
		$this->hasLayout = 1;
	}
	function get_rightMargin() { return twip2nmb($this->rightMargin); }

	function set_indent($indent) {
		$this->indent = nmb2Twip($indent);
		$this->hasLayout = 1;
	}
	function get_indent() { return twip2nmb($this->indent); }

	function set_leading($leading) {
		$this->leading = nmb2Twip($leading);
		$this->hasLayout = 1;
	}
	function get_leading() { return twip2nmb($this->leading); }

	// sets one or more layout settings
	// from a given associative array
	function set_layout($lAr){
		$this->hasLayout = 1;
 		if($lAr["leftMargin"]) $this->leftMargin = nmb2Twip($lAr["leftMargin"]);
		if($lAr["rightMargin"]) $this->rightMargin = nmb2Twip($lAr["rightMargin"]);
		if($lAr["indent"]) $this->indent = nmb2Twip($lAr["indent"]);
		if($lAr["leading"]) $this->leading = nmb2Twip($lAr["leading"]);
	}

	function get_layout(){

		$lAr = array();
 		$lAr["leftMargin"] = twip2nmb($this->leftMargin);
		$lAr["rightMargin"] = twip2nmb($this->rightMargin);
		$lAr["indent"] = twip2nmb($this->indent);
		$lAr["leading"] = twip2nmb($this->leading);

		return $lAr;
	}

	function clear_layout(){
		$this->hasLayout = 0;
 		$this->leftMargin = 0;
		$this->rightMargin = 0;
		$this->indent = 0;
		$this->leading = 0;
	}

	function set_variableName($variableName) { $this->variableName = $variableName; }
	function get_variableName() { return $this->variableName; }

	function set_initialText($initialText){
		$this->initialText = $initialText;
		$this->hasText = 1;
	}
	function get_initialText() { return $this->initialText; }

	function clear_text(){
		$this->hasText = 0;
		$this->initialText = "";
	}

	function set_text($initialText){
		$this->initialText = $initialText;
		$this->hasText = 1;
	}
	function get_text() { return $this->initialText; }

	//
	function set_width($width){
		$this->width = nmb2twip($width);
		$this->update_bounds();
	}
	function set_height($height){
		$this->height = nmb2twip($height);
		$this->update_bounds();
	}

	//
	function get_placeDepth(){ return $this->po->get_placeDepth(); }

	// set translation data for placeObject2
	function move($x, $y, $isChange = false){
		$this->po->set_position($x, $y, $isChange);
	}

	// set scale data for placeObject2
	function scale($scaleX, $scaleY, $isChange = false){
		$this->po->set_scale($scaleX, $scaleY, $isChange);
	}

	// set rotation data for placeObject2
	function rotate($rotation, $isChange = false){
		$this->po->set_rotation($rotation, $isChange);
	}

	//
	function set_textField_data($detd = array()){

		if(count($detd)) $this->get_textField_data($detd);
		else $detd = $this->fetch_assoc();

		$this->tagData = write_textField_data($detd);

		return $this->tagData;
	}

	//
	function get_textField_data($detd = array()){

		if(!count($detd)) $detd = read_textField_data($this->tagData);

		$this->itemID = $detd["itemID"];
		$this->bounds = new MKRect("",
									$detd["bounds"]["xmin"], $detd["bounds"]["xmax"],
									$detd["bounds"]["ymin"], $detd["bounds"]["ymax"]);

		$this->hasText 		= $detd["hasText"];
		$this->wordWrap		= $detd["wordWrap"];
		$this->multiline	= $detd["multiline"];
		$this->password		= $detd["password"];
		$this->readOnly		= $detd["readOnly"];
		$this->hasTextColor = $detd["hasTextColor"];
		$this->hasMaxLength = $detd["hasMaxLength"];
		$this->hasFont		= $detd["hasFont"];
		$this->hasFontClass	= $detd["hasFontClass"];
		$this->autoSize		= $detd["autoSize"];
		$this->hasLayout	= $detd["hasLayout"];
		$this->noSelect		= $detd["noSelect"];
		$this->border		= $detd["border"];
		$this->wasStatic	= $detd["wasStatic"];
		$this->html			= $detd["html"];
		$this->useOutlines	= $detd["useOutlines"];

		if($detd["hasFont"]) {
			$this->fontID = $detd["fontID"];
			$this->fontHeight = $detd["fontHeight"];
		}

		if($detd["hasFontClass"]) {
			$this->fontClass = $detd["fontClass"];
		}

		if($detd["hasTextColor"]){
			$this->textColor = new MKColor();
			$this->textColor->set_color($detd["textColor"]);
		}

		if($detd["hasMaxLength"])
			$this->maxLength = $detd["maxLength"];

		if($detd["hasLayout"]){

			$this->align = $detd["align"];
			$this->leftMargin = $detd["leftMargin"];
			$this->rightMargin = $detd["rightMargin"];
			$this->indent = $detd["indent"];
			$this->leading = $detd["leading"];
		}

		$this->variableName = $detd["variableName"];

		if($detd["hasText"])
			$this->initialText = $detd["initialText"];
	}

	//
	function fetch_assoc(){

		$detd = array();

		$detd["itemID"]			 = $this->itemID;
		$detd["bounds"]			 = $this->bounds->fetch_assoc();

		$detd["hasText"]	 	 = $this->hasText;
		$detd["wordWrap"]	 	 = $this->wordWrap;
		$detd["multiline"]	 	 = $this->multiline;
		$detd["password"]	 	 = $this->password;
		$detd["readOnly"]		 = $this->readOnly;
		$detd["hasTextColor"]	 = $this->hasTextColor;
		$detd["hasMaxLength"]	 = $this->hasMaxLength;
		$detd["hasFont"]	  	 = $this->hasFont;
		$detd["hasFontClass"]  	 = $this->hasFontClass;
		$detd["reserved1"]	 	 = 0;
		$detd["autoSize"]	  	 = $this->autoSize;
		$detd["hasLayout"]	  	 = $this->hasLayout;
		$detd["noSelect"]	 	 = $this->noSelect;
		$detd["border"]		 	 = $this->border;
		$detd["wasStatic"]	   	 = $this->wasStatic;
		$detd["html"]		 	 = $this->html;
		$detd["useOutlines"]	 = $this->useOutlines;

		if($this->hasFont) {
			$detd["fontID"]	     = $this->fontID;
			$detd["fontHeight"]  = $this->fontHeight;
		}

		if($this->hasFontClass) {
			$detd["fontClass"]	  = $this->fontClass;
		}

		if($this->hasTextColor)
			$detd["textColor"]	 = $this->textColor->get_color();

		if($this->hasMaxLength)
			$detd["maxLength"]	 = $this->maxLength;

		if($this->hasLayout){

			$detd["align"]	     = $this->align;
			$detd["leftMargin"]  = $this->leftMargin;
			$detd["rightMargin"] = $this->rightMargin;
			$detd["indent"]		 = $this->indent;
			$detd["leading"]	 = $this->leading;
		}

		$detd["variableName"]	 = $this->variableName;

		if($this->hasText)
			$detd["initialText"] = $this->initialText;

		return $detd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "textField"){

		$xmlStr = $includeHeader ? XML_HEADER : "";
		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";
		$xmlStr .= "id=\"" .$this->itemID ."\" ";

		if(strlen($this->variableName))
			$xmlStr .= "variableName=\"" .$this->variableName ."\" ";

		$xmlStr .= "wordWrap=\"" .$this->wordWrap ."\" ";
		$xmlStr .= "multiline=\"" .$this->multiline ."\" ";
		$xmlStr .= "password=\"" .$this->password ."\" ";
		$xmlStr .= "readOnly=\"" .$this->readOnly ."\" ";

		if($this->hasTextColor){
			$cAr = $this->textColor->fetch_assoc();

			$xmlStr .= "textColor=\"" .get_html_color($cAr) ."\" ";

			if(isset($cAr["alpha"]) && $cAr["alpha"] < 0xff)
				$xmlStr .= "textAlpha=\"" .$cAr["alpha"] ."\" ";
		}

		//$xmlStr .= "hasTextColor=\"" .$this->hasTextColor ."\" ";

		if($this->hasMaxLength)
			$xmlStr .= "maxLength=\"" .$this->maxLength ."\" ";

		$xmlStr .= "hasFont=\"" .$this->hasFont ."\" ";
		$xmlStr .= "autoSize=\"" .$this->autoSize ."\" ";
		$xmlStr .= "noSelect=\"" .$this->noSelect ."\" ";
		$xmlStr .= "border=\"" .$this->border ."\" ";
		$xmlStr .= "wasStatic=\"" .$this->wasStatic ."\" ";
		$xmlStr .= "html=\"" .$this->html ."\" ";
		$xmlStr .= "useOutlines=\"" .$this->useOutlines ."\">";

		$xmlStr .= $this->bounds->fetch_xml(false, $tabLevel, "tfRect");

		$pfx = get_xml_indent_row(++$tabLevel);

		if($this->hasFont) {
			$xmlStr .= $pfx ."<font ID=\"" .$this->fontID ."\" ";
			$xmlStr .= "height=\"" .twip2nmb($this->fontHeight) ."px\" ";
		}

		if($this->hasFontClass) {
			$xmlStr .= "fontClass=\" ".$this->fontClass ."\" ";
		}

		$xmlStr .= "/>";

		if($this->hasLayout){

			$xmlStr .= $pfx ."<layout ";
			$xmlStr .= "align=\"" .$this->align ."\" ";
			$xmlStr .= "leftMargin=\"" .$this->leftMargin ."\" ";
			$xmlStr .= "rightMargin=\"" .$this->rightMargin ."\" ";
			$xmlStr .= "indent=\"" .$this->indent ."\" ";
			$xmlStr .= "leading=\"" .$this->leading ."\" />";
		}

		if($this->hasText){
			$xmlStr .= $pfx ."<text>";
			$pfx = get_xml_indent_row(++$tabLevel);
			$xmlStr .= $pfx ."<![CDATA[" .$this->initialText ."]]>";
			$pfx = get_xml_indent_row(--$tabLevel);
			$xmlStr .= $pfx ."</text>";
		}

		$pfx = get_xml_indent_row(--$tabLevel);
		$xmlStr .= $pfx ."</" .$nodeName .">";

		return $xmlStr;
	}

	//
	function update_tagData(){
		return $this->set_textField_data();
	}

	// returns placeObject2 tagData
	function update_place_tagData($replacingDepth = -1){
		return $this->po->update_tagData($replacingDepth);
	}
}

/**
 * class wrapper for defineFont2/3 tag
 */
class MKFontContainer extends MKTagHeader {

	var $tagData = "";

	//alias of itemID
	//var $fontID;				// UI16 ID for this font character
	var $fontFlagsHasLayout;	// UB[1] Has font metrics/layout information
	var $fontFlagsShiftJIS;		// UB[1] ShiftJIS encoding
	var $fontFlagsSmallText;	// UB[1] SWF 7 or later:
								// Font is small. Character glyphs
								// are aligned on pixel boundaries
								// for dynamic and input text.
	var $fontFlagsANSI;			// UB[1] ANSI encoding
	var $fontFlagsWideOffsets;	// UB[1] If 1, uses 32 bit offsets
	var $fontFlagsWideCodes = 1; // UB[1] If 1, font uses 16-bit codes,
								// otherwise font uses 8 bit codes
	var $fontFlagsItalic;		// UB[1] Italic Font
	var $fontFlagsBold;			// UB[1] Bold Font
	var $languageCode = 1;		// LANGCODE SWF 5 or earlier:
								// always 0
								// SWF 6 or later: language code
	var $fontNameLen;			// UI8 Length of name
	var $fontName;				// UI8[FontNameLen] Name of font (see DefineFontInfo)

	var $numGlyphs = 0;			// UI16 Count of glyphs in font
								// May be zero for device fonts
	var $offsetTable;			// If FontFlagsWideOffsets UI32[NumGlyphs]
								// Otherwise UI16[NumGlyphs]
								// Same as in DefineFont
	var $codeTableOffset;		// If FontFlagsWideOffsets UI32
								// Otherwise UI16
								// Byte count from start of
								// OffsetTable to start of CodeTable
	var $glyphShapeTable;		// SHAPE[NumGlyphs] Same as in DefineFont
	var $codeTable;				// If FontFlagsWideCodes UI16[NumGlyphs]
								// Otherwise UI8[NumGlyphs]
								// Sorted in ascending order
								// Always UCS-2 in SWF 6 or later
	var $fontAscent;			// If FontFlagsHasLayout SI16 Font ascender height
	var $fontDescent;			// If FontFlagsHasLayout SI16 Font descender height
	var $fontLeading;			// If FontFlagsHasLayout SI16 Font leading height (see below)
	var $fontAdvanceTable;		// If FontFlagsHasLayout SI16[NumGlyphs]
								// Advance value to be used for
								// each glyph in dynamic glyph text
	var $fontBoundsTable;		// If FontFlagsHasLayout
								// RECT[NumGlyphs]
								// Not used in Flash Player
								// through version 7 (but must be present)
	var $kerningCount;			// If FontFlagsHasLayout UI16 Not used in Flash Player
								// through version 7 (always set to
								// 0 to save space)
	var $fontKerningTable;		// If FontFlagsHasLayout
								// KERNINGRECORD [KerningCount]
								// Not used in Flash Player
								// through version 7 (omit with
								// KerningCount of 0)

	var $linkage;				// linkage

	// the constructor
	function MKFontContainer($tagData = "", $itemID = 1){

		$this->itemID = $itemID;

		if(strlen($tagData)){
			parent::MKTagHeader(substr($tagData, 0, 10));
			$this->tagData = $tagData;
			$this->get_font_container_data();
		}
	}

	function set_fontID($fontID) {$this->itemID = $fontID; }
	function get_fontID() {return $this->itemID; }

	function set_fontFlagsHasLayout($fontFlagsHasLayout) {$this->fontFlagsHasLayout = $fontFlagsHasLayout; }
	function get_fontFlagsHasLayout() { return $this->fontFlagsHasLayout; }

	function set_fontFlagsShiftJIS($fontFlagsShiftJIS) { $this->fontFlagsShiftJIS = $fontFlagsShiftJIS; }
	function get_fontFlagsShiftJIS() { return $this->fontFlagsShiftJIS; }

	function set_fontFlagsSmallText($fontFlagsSmallText) { $this->fontFlagsSmallText = $fontFlagsSmallText; }
	function get_fontFlagsSmallText() { return $this->fontFlagsSmallText; }

	function set_fontFlagsANSI($fontFlagsANSI) { $this->fontFlagsANSI = $fontFlagsANSI; }
	function get_fontFlagsANSI() { return $this->fontFlagsANSI; }

	function set_fontFlagsWideOffsets($fontFlagsWideOffsets) { $this->fontFlagsWideOffsets = $fontFlagsWideOffsets; }
	function get_fontFlagsWideOffsets() { return $this->fontFlagsWideOffsets; }

	function set_fontFlagsWideCodes($fontFlagsWideCodes) { $this->fontFlagsWideOffsets = $fontFlagsWideCodes; }
	function get_fontFlagsWideCodes() { return $this->fontFlagsWideOffsets; }

	function set_fontFlagsItalic($fontFlagsItalic) { $this->fontFlagsItalic = $fontFlagsItalic; }
	function get_fontFlagsItalic() { return $this->fontFlagsItalic; }

	function set_fontFlagsBold($fontFlagsBold) { $this->fontFlagsBold = $fontFlagsBold; }
	function get_fontFlagsBold() { return $this->fontFlagsBold; }

	function set_languageCode($languageCode) { $this->languageCode = $languageCode; }
	function get_languageCode() { return $this->languageCode; }

	function set_fontNameLen($fontNameLen) { $this->fontNameLen = $fontNameLen; }
	function get_fontNameLen() { return $this->fontNameLen; }

	function set_fontName($fontName) { $this->fontName = $fontName; }
	function get_fontName() { return $this->fontName; }

	function set_numGlyphs($numGlyphs) { $this->numGlyphs = $numGlyphs; }
	function get_numGlyphs() { return $this->numGlyphs; }

	function set_offsetTable($offsetTable) { $this->offsetTable = $offsetTable; }
	function get_offsetTable() { return $this->offsetTable; }

	function set_codeTableOffset($codeTableOffset) { $this->codeTableOffset = $codeTableOffset; }
	function get_codeTableOffset() { return $this->codeTableOffset; }

	function set_glyphShapeTable($glyphShapeTable) { $this->glyphShapeTable = $glyphShapeTable; }
	function get_glyphShapeTable() { return $this->glyphShapeTable; }

	function set_codeTable($codeTable) { $this->codeTable = $codeTable; }
	function get_codeTable() { return $this->codeTable; }

	function set_fontAscent($fontAscent) { $this->fontAscent = $fontAscent; }
	function get_fontAscent() { return $this->fontAscent; }

	function set_fontDescent($fontDescent) { $this->fontDescent = $fontDescent; }
	function get_fontDescent() { return $this->fontDescent; }

	function set_fontLeading($fontLeading) { $this->fontLeading = $fontLeading; }
	function get_fontLeading() { return $this->fontLeading; }

	function set_fontAdvanceTable($fontAdvanceTable) { $this->fontAdvanceTable = $fontAdvanceTable; }
	function get_fontAdvanceTable() { return $this->fontAdvanceTable; }

	function set_fontBoundsTable($fontBoundsTable) { $this->fontBoundsTable = $fontBoundsTable; }
	function get_fontBoundsTable() { return $this->fontBoundsTable; }

	function set_kerningCount($kerningCount) { $this->kerningCount = $kerningCount; }
	function get_kerningCount() { return $this->kerningCount; }

	function set_fontKerningTable($fontKerningTable) { $this->fontKerningTable = $fontKerningTable; }
	function get_fontKerningTable() { return $this->fontKerningTable; }

	//
	function update_linkage($linkageName = ""){
		if(!isset($this->linkage)) $this->linkage = new MKExportAssets();
		$this->linkage->update_asset($this->itemID, $linkageName, 0);

		// prevent empty linkage name
		// in case it provides an automated generated name
		$linkageRef = $this->linkage->get_assetAt(0);
		if(!strlen($linkageRef["name"])) $linkageName = "fontID" .$this->itemID;
		$this->linkage->update_asset($this->itemID, $linkageName, 0);
		return $this->linkage->update_tagData();

	}

	//
	function set_linkage_name($linkageName = ""){
		return $this->update_linkage($linkageName);
	}

	//
	function set_font_container_data($fcd = array()){

		if(count($fcd)){
			$this->get_font_container_data($fcd);
		}
		else {
			$fcd = array();
			$fcd = $this->fetch_assoc();
		}

		if(strlen($this->tagData)){
			/*
			$fcFlags = write_defineFont2_data($fcd, true);
			$fLength = strlen($fcFlags) + 6;
			$bData = substr($this->tagData, $fLength);
			$fcBody = $fcFlags .$bData;
			$fLength = strlen($fcBody);
			$this->tagData = SWFTag_long_header(FONT2, $fLength) .$fcBody;
			*/
		}
		else $this->tagData = write_defineFont_data($fcd);

		return $this->tagData;
	}

	function get_font_container_data($fcd = array()){

		if(!count($fcd)){
			$fcd = array();
			$fcd = read_defineFont_data($this->tagData);
		}

		$this->itemID				= $fcd["itemID"];
		$this->fontFlagsHasLayout	= $fcd["fontFlagsHasLayout"];
		$this->fontFlagsShiftJIS	= $fcd["fontFlagsShiftJIS"];
		$this->fontFlagsSmallText	= $fcd["fontFlagsSmallText"];
		$this->fontFlagsANSI		= $fcd["fontFlagsANSI"];
		$this->fontFlagsWideOffsets	= $fcd["fontFlagsWideOffsets"];
		$this->fontFlagsWideCodes	= $fcd["fontFlagsWideCodes"];
		$this->fontFlagsItalic		= $fcd["fontFlagsItalic"];
		$this->fontFlagsBold		= $fcd["fontFlagsBold"];
		$this->languageCode			= $fcd["languageCode"];
		$this->fontNameLen			= $fcd["fontNameLen"];
		$this->fontName				= $fcd["fontName"];
		$this->numGlyphs			= $fcd["numGlyphs"];
		$this->offsetTable			= $fcd["offsetTable"];
		$this->codeTableOffset		= $fcd["codeTableOffset"];

		/* TODO */
	}

	//
	function load_mkfont_from_file($mkfFile, $workingDir = SERVER_MKFONTS){

		$fName = $workingDir .$mkfFile;

		if(!file_exists($fName)) return;

		$fin = fopen($fName, "rb");
		$fBody = swf_word($this->itemID);
		$fBody .= fread($fin, filesize($fName));
		fclose($fin);

		$fLength = strlen($fBody);
		if(!$fLength) return;

		$this->tagData = SWFTag_long_header(FONT2, $fLength) . $fBody;
		$this->get_font_container_data();
	}


	//
	function update_tagData(){
		return $this->set_font_container_data();
	}

	//
	function update_linkage_tagData(){
		$this->update_linkage();
		return $this->linkage->update_tagData();
	}

	//
	function fetch_assoc(){

		/* TODO */

	$dfd = array();

	$dfd["tagID"]				 = $this->tagID;
	$dfd["itemID"]				 = $this->itemID;
	$dfd["fontFlagsHasLayout"]	 = $this->fontFlagsHasLayout;
	$dfd["fontFlagsShiftJIS"]	 = $this->fontFlagsShiftJIS;
	$dfd["fontFlagsSmallText"]	 = $this->fontFlagsSmallText;
	$dfd["fontFlagsANSI"]		 = $this->fontFlagsANSI;
	$dfd["fontFlagsWideOffsets"] = $this->fontFlagsWideOffsets;
	$dfd["fontFlagsWideCodes"]	 = $this->fontFlagsWideCodes;
	$dfd["fontFlagsItalic"]		 = $this->fontFlagsItalic;
	$dfd["fontFlagsBold"]		 = $this->fontFlagsBold;
	$dfd["languageCode"]		 = $this->languageCode;
	$dfd["fontNameLen"]			 = $this->fontNameLen;
	$dfd["fontName"]			 = $this->fontName;
	$dfd["numGlyphs"]			 = $this->numGlyphs;
	$dfd["offsetTable"]			 = $this->offsetTable;
	$dfd["codeTableOffset"]		 = $this->codeTableOffset;

	/*
	$dfd["glyphShapeTable"]		 = $this->glyphShapeTable;
	$dfd["codeTable"]			 = $this->codeTable;
	$dfd["fontAscent"]			 = $this->fontAscent;
	$dfd["fontDescent"]			 = $this->fontDescent;
	$dfd["fontLeading"]			 = $this->fontLeading;
	$dfd["fontAdvanceTable"]	 = $this->fontAdvanceTable;
	$dfd["fontBoundsTable"]		 = $this->fontBoundsTable;
	$dfd["kerningCount"]		 = $this->kerningCount;
	$dfd["fontKerningTable"]	 = $this->fontKerningTable;
	*/

	return $dfd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "fontItem"){
		/* TODO */

		$dfd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";
		//$pfx = get_xml_indent_row(++$tabLevel);

		$xmlStr .= "id=\"" . $dfd["itemID"] ."\" ";

		//$xmlStr .= "	$dfd["fontFlagsHasLayout"]
		if($dfd["tagID"] == FONT3)	$xmlStr .= "flashType=\"1\" ";

		if($dfd["fontFlagsShiftJIS"])	 $xmlStr .= "ffShiftJIS=\"1\" ";
		if($dfd["fontFlagsSmallText"])	 $xmlStr .= "smallText=\"1\" ";
		if($dfd["fontFlagsANSI"])		 $xmlStr .= "ffANSI=\"1\" ";
		if($dfd["fontFlagsWideOffsets"]) $xmlStr .= "ffWideOffset=\"1\" ";
		if($dfd["fontFlagsWideCodes"])	 $xmlStr .= "ffWideCodes=\"1\" ";
		if($dfd["fontFlagsItalic"])		 $xmlStr .= "italic=\"1\" ";
		if($dfd["fontFlagsBold"])		 $xmlStr .= "bold=\"1\" ";

		$xmlStr .= "langCode=\"" .$dfd["languageCode"] ."\" ";
		//$xmlStr .= "	$dfd["fontNameLen"]
		$xmlStr .= "fontName=\"" .$dfd["fontName"] ."\" ";
		if(!$dfd["numGlyphs"]) $xmlStr .= "useDeviceFont=\"1\" ";
		else $xmlStr .= "glyphsUsed=\"" .$dfd["numGlyphs"] ."\" ";
		//$xmlStr .= "	$dfd["offsetTable"]
		//$xmlStr .= "	$dfd["codeTableOffset"]
		$xmlStr .= ">";


		//$pfx = get_xml_indent_row(--$tabLevel);
		$xmlStr .= $pfx ."</" .$nodeName .">";


		return $xmlStr;
	}
}


/**
 * DefineFontAlignZone
 * swf8, for FlashType implementation
 */
class MKFontAlignZones extends MKTagHeader{

	var $tagData = "";

	//alias of itemID
	//var $fontID;				// it is relevant to a fontID
								// in defineFont3 tag elsewhere

	var $csmTableHint;			// UB[2] Font thickness hint. Refers
								//       to the thickness of the typical
								//       stroke used in the font.
								//       0 = thin
								//       1 = medium
								//       2 = thick
								//       Flash Player maintains a
								//       selection of CSM tables for
								//       many fonts. However, if the
								//       font is not found in Flash
								//       Player's internal table, this
								//       hint is used to choose an
								//       appropriate table.

	var $reserved = 0;			// UB[6] Must be 0.

	var $zoneTable = array();	// ZONERECORD[GlyphCount] Alignment zone
								// information for each glyph.

	// constructor
	function MKFontAlignZones ($tagData = "", $fontID = 1){

		$this->tagData = $tagData;
		$this->itemID = $fontID;

		if(strlen($tagData)){
			parent::MKTagHeader(substr($tagData, 0, 10));
			$this->tagData = $tagData;
			$this->get_defineFontAlignZones_data();
			return;
		}
	}

	//
	function set_fontID($fontID) {$this->itemID = $fontID; }
	function get_fontID() {return $this->itemID; }

	//
	function set_zoneTable($zoneTable = array()) {$this->zoneTable = $zoneTable; }
	function get_zoneTable() {return $this->zoneTable; }


	function set_defineFontAlignZones_data($dfazd = array()){

		if(count($dfazd)) $this->get_font_container_data($dfazd);
		else $dfazd = $this->fetch_assoc();

		$this->tagData = write_defineFontAlignZones_data($dfazd);

		return $this->tagData;

	}

	function get_defineFontAlignZones_data($dfazd = array()){

		if(!count($dfazd)) $dfazd = read_defineFontAlignZones_data($this->tagData);

		$this->itemID			= $dfazd["itemID"];
		$this->csmTableHint		= $dfazd["csmTableHint"];

		//$this->zoneTable		= $dfazd["zoneTable"];

		$this->zoneTable = array();

		foreach($dfazd["zoneTable"] as $zr)
			$this->zoneTable[] = new MKZoneRecord("", $zr);
	}

	//
	function update_tagData(){

	}

	//
	function fetch_assoc(){

		$dfazd = array();

		$dfazd["fontID"] = $this->itemID;
		$dfazd["itemID"] = $this->itemID;

		$dfazd["csmTableHint"] = $this->csmTableHint;
		$dfazd["zoneTable"] = array();

		//foreach($this->zoneTable as $zr)
		//	$dfazd["zoneTable"][] = $zr->fetch_assoc();

		$dfazd["zoneTable"] = $this->zoneTable;

		return $dfazd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "fontAlignZones", $hexDump = false, $showChildNodes = false){

		if(!strlen($nodeName)) $nodeName = "fontAlignZones";

		$dfazd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "fontID=\"" . $dfazd["itemID"] ."\" ";
		$xmlStr .= "zoneRecordCount=\"". count($this->zoneTable) ."\" >";
		$xmlStr .= get_xml_indent_row(++$tabLevel);

		if($hexDump) {
			$xmlStr .= "<hexData>";
			$xmlStr .= hex_dump($this->tagData, true);
			$xmlStr .= "</hexData>";
		}


		if($showChildNodes) {
			$xmlStr .= "<zoneTable>";
			$xmlStr .= get_xml_indent_row(++$tabLevel);

			foreach($dfazd["zoneTable"] as $zr)
				$xmlStr .= $zr->fetch_xml(false, $tabLevel);

			$xmlStr .= get_xml_indent_row(--$tabLevel);
			$xmlStr .= "</zoneTable>";
		}
		$xmlStr .= get_xml_indent_row(--$tabLevel);
		$xmlStr .= "</" .$nodeName .">";

		return $xmlStr;
	}
}

/**
 * TEXTRECORD structure
 */
class MKTextRecord {

	var $binData = "";

	var $textRecordType = 1;		// UB[1] Always 1.
	var $styleFlagsReserved = 0;	// UB[3] Always 0.
	var $styleFlagsHasFont;			// UB[1] 1 if text font specified.
	var $styleFlagsHasColor;		// UB[1] 1 if text color specified.
	var $styleFlagsHasYOffset;		// UB[1] 1 if y offset specified.
	var $styleFlagsHasXOffset;		// UB[1] 1 if x offset specified.

	var $fontID;					// If StyleFlagsHasFont UI16 Font ID for following text.
	var $textColor;					// If StyleFlagsHasColor RGB
									// If this record is part of a
									// DefineText2 tag then RGBA
									// Font color for following text.
	var $xOffset;					// If StyleFlagsHasXOffset SI16 x offset for following text.
	var $yOffset;					// If StyleFlagsHasYOffset SI16 y offset for following text.
	var $textHeight;				// If hasFont UI16 Font height for following text.
	var $glyphCount;				// UI8 Number of glyphs in record.
	var $glyphEntries;				// GLYPHENTRY[GlyphCount] Glyph entry (see following).

	function MKTextRecord($binData = "", $trd = array()){

	}
}


/**
 * GLIPHENTRY structure
 */
class MKGliphEntry {

	var $glyphIndex;	// UB[GlyphBits] Glyph index into current font.
	var $glyphAdvance;	// SB[AdvanceBits] x advance value for glyph.

	function MKGliphEntry($binData = "", $ged = array()){
		$this->binData = $binData;
		$this->get_gliphEntry_data($ged);
	}

	//
	function set_gliphIndex($gliphIndex) { $this->gliphIndex = $gliphIndex; }
	function get_gliphIndex() { return $this->gliphIndex; }

	//
	function set_gliphAdvance($gliphAdvance) { $this->gliphAdvance = $gliphAdvance; }
	function get_gliphAdvance() { return $this->gliphAdvance; }

	function set_gliphEntry_data($ged = array()){

		if(count($ged)) $this->get_zoneRecord_data($ged);
		else $dfazd = $this->fetch_assoc();

		$this->binData = write_gliphEntry_data($ged);

		return $this->binData;
	}

	function get_gliphEntry_data($ged = array()){

		if(!count($ged)) $zrd = read_gliphEntry_data($this->binData);

		$this->glyphIndex = $ged["glyphIndex"];
		$this->glyphAdvance = $ged["glyphAdvance"];
	}

	//
	function fetch_assoc(){
		$ged = array();

		$ged["glyphIndex"] = $this->glyphIndex;
		$ged["glyphAdvance"] = $this->glyphAdvance;

		return $ged;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "gliphEntry"){

		$ged = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "glyphIndex=\"" . $ged["numZoneData"] ."\" ";
		$xmlStr .= "glyphAdvance=\"" . $ged["zoneMaskX"] ."\" />";

		return $xmlStr;
	}
}

//------------- FLASHTYPE STRUCTURES --------------------

/**
 *
 */
class MKZoneRecord {

	var $binData = "";

	var $numZoneData = 2;		// UI8 Number of ZoneData entries. Always 2

	var $zoneData = array();	// ZONEDATA[NumZoneData]
								// Compressed alignment zone information

	var $zoneMaskX;				// UB[1] Set if there are X alignment zones
	var $zoneMaskY;				// UB[1] Set if there are Y alignment zones
	var $reserved = 0;			// UB[6] Must be 0.

	// constructor
	function MKZoneRecord($buf = "", $zrd = array()){
		$this->binData = $buf;
		$this->get_zoneRecord_data($zrd);
	}

	function set_zoneRecord_data($zrd = array()){

		if(count($zrd)) $this->get_zoneRecord_data($zrd);
		else $dfazd = $this->fetch_assoc();

		$this->binData = write_zoneRecord_data($zrd);

		return $this->binData;

	}

	function get_zoneRecord_data($zrd = array()){

		if(!count($zrd)) $zrd = read_zoneRecord_data($this->tagData);

		$this->numZoneData = $zrd["numZoneData"];
		$this->zoneMaskX = $zrd["zoneMaskX"];
		$this->zoneMaskY = $zrd["zoneMaskY"];

		foreach($zrd["zoneData"] as $zd){
			$this->zoneData[] = new MKZoneData("", $zd);
		}
	}

	//
	function fetch_assoc(){
		$zrd = array();

		$zrd["numZoneData"] = $this->numZoneData;
		$zrd["zoneMaskX"] = $this->zoneMaskX;
		$zrd["zoneMaskY"] = $this->zoneMaskY;

		$zrd["zoneData"] = array();

		//foreach($this->zoneData as $zd)
		//	$zrd["zoneData"][] = $zd->fetch_assoc();

		$zrd["zoneData"] = $this->zoneData;

		return $zrd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "zoneRecord"){

		$zrd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "numZoneData=\"" . $zrd["numZoneData"] ."\" ";
		$xmlStr .= "zoneMaskX=\"" . $zrd["zoneMaskX"] ."\" ";
		$xmlStr .= "zoneMaskY=\"" . $zrd["zoneMaskY"] ."\" >";

		$xmlStr .= get_xml_indent_row(++$tabLevel);
		$xmlStr .= "<zoneData>";
		$xmlStr .= get_xml_indent_row(++$tabLevel);

		foreach($zrd["zoneData"] as $zd)
			$xmlStr .= $zd->fetch_xml(false, $tabLevel);

		$xmlStr .= get_xml_indent_row(--$tabLevel);
		$xmlStr .= "</zoneData>";
		$xmlStr .= get_xml_indent_row(--$tabLevel);
		$xmlStr .= "</" .$nodeName .">";

		return $xmlStr;
	}
}

/**
 *
 */
class MKZoneData {

	var $binData = "";

	var $alignmentCoordinate;		// FLOAT16 X (left) or Y (baseline)
									// coordinate of the alignment zone
	var $zdRange;						// FLOAT16 Width or height of the
									// alignment zone

	// constructor
	function MKZoneData($buf = "", $zd = array()){
		$this->binData = $buf;
		$this->get_zoneData_data($zd);
	}

	//
	function set_alignmentCoordinate($alignmentCoordinate){ $this->alignmentCoordinate = $alignmentCoordinate; }
	function get_alignmentCoordinate(){ return $this->alignmentCoordinate; }

	//
	function set_range($zdRange){ $this->zdRange = $zdRange; }
	function get_range(){ return $this->zdRange; }


	function set_zoneData_data($zdd = array()){

		if(!count($zdd)) $zdd = $this->fetch_assoc();

		$this->binData = write_zoneData_data($zdd);

		return $this->binData();
	}

	function get_zoneData_data($zdd = array()){

		if(!count($zdd)) $zdd = read_zoneData_data($this->binData);

		$this->alignmentCoordinate = $zdd["alignmentCoordinate"];
		$this->zdRange = $zdd["range"];
	}

	//
	function fetch_assoc(){
		$zdd = array();

		$zdd["alignmentCoordinate"] = $this->alignmentCoordinate;
		$zdd["range"] = $this->zdRange;

		return $zdd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "zdItem"){

		$zdd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "alignmentCoordinate=\"" . $zdd["alignmentCoordinate"] ."\" ";
		$xmlStr .= "range=\"" . $zdd["range"] ."\" />";

		return $xmlStr;
	}
}


/**
 *
 */
class MKCSMTextSettings extends MKTagHeader {

	var $tagData = "";

	// alias of itemID
	//var $textID;		// ID for the DefineText, DefineText2, or
						// DefineEditText to which this tag applies.

	var $useFlashType;	// UB[2] 0 = use normal renderer.
						//       1 = use FlashType renderer

	var $gridFit;		// UB[3] 0 = Do not use grid fitting.
						//           AlignmentZones and LCD
						//           sub-pixel information will not be used.
						//       1 = Pixel grid fit. Only
						//           supported for left-aligned
						//           dynamic text. This setting
						//           provides the ultimate in
						//           FlashType readability, with
						//           crisp letters aligned to pixels.
						//       2 = Sub-pixel grid fit. Align
						//           letters to the 1/3 pixel used
						//           by LCD monitors. Can also
						//           improve quality for CRT output.

	var $gfReserved = 0;	// UB[3] Must be 0.
	var $thickness;		// F32 The thickness attribute for the
						//     associated text field. Set to 0.0
						//     to use the default
						//     (anti-aliasing table) value.
	var $sharpness;		// F32 The sharpness attribute for
						//     the associated text field. Set to 0.0
						//     to use the default
						//     (anti-aliasing table) value.
	var $reserved = 0;	// UI8 Must be 0.

	// the constructor
	function MKCSMTextSettings($tagData = "", $textID = 1){
		$this->tagData = $tagData;
		$this->itemID = $textID;

		if(strlen($tagData)) $this->get_csmTextSettings_data();
	}

	function set_csmTextSettings_data($ctsd = array()){

		if(!count($ctsd)) $ctsd = $this->fetch_assoc();

		$this->tagData = write_csmTextSettings_data($ctsd);

		return $this->tagData();
	}

	function get_csmTextSettings_data($ctsd = array()){

		if(!count($ctsd)) $ctsd = read_csmTextSettings_data($this->tagData);

		$this->itemID = $ctsd["itemID"];
		$this->textID = $ctsd["textID"];
		$this->useFlashType = $ctsd["useFlashType"];
		$this->gridFit = $ctsd["gridFit"];
		$this->thickness = $ctsd["thickness"];
		$this->sharpness = $ctsd["sharpness"];
	}

	//
	function fetch_assoc(){

		$ctsd = array();
		$ctsd["itemID"] 	  = $this->itemID;
		$ctsd["textID"] 	  = $this->textID;
		$ctsd["useFlashType"] = $this->useFlashType;
		$ctsd["gridFit"] 	  = $this->gridFit;
		$ctsd["thickness"] 	  = $this->thickness;
		$ctsd["sharpness"]	  = $this->sharpness;

		return $ctsd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "csmTextSettings"){

		$ctsd = $this->fetch_assoc();
		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "textID=\"" . $ctsd["textID"] ."\" ";
		$xmlStr .= "useFlashType=\"" . $ctsd["useFlashType"] ."\" ";
		$xmlStr .= "gridFit=\"" . $ctsd["gridFit"] ."\" ";
		$xmlStr .= "thickness=\"" . $ctsd["thickness"] ."\" ";
		$xmlStr .= "sharpness=\"" . $ctsd["sharpness"] ."\" />";

		return $xmlStr;
	}
}

/**
 *
 */
class MKKerningRecord {

	var $binData = "";

	var $ffWideCodes;			// private boolean

	var $fontKerningCode1;		// If FontFlagsWideCodes UI16 Otherwise UI8
								// Character code of the left character.
	var $fontKerningCode2;		// If FontFlagsWideCodes UI16 Otherwise UI8
								// Character code of the right 	character.
	var $fontKerningAdjustment;	// SI16 Adjustment relative to left
								// character�s advance value.
	// constructor
	function MKKerningRecord($binData = "", $ffWideCodes = true){
		/* TODO implement constructor */
	}
}


class MKFontName extends MKTagHeader {

	var $tagData = "";

	var $fontID = 1; 			//UI16 ID for this font to which this refers
	var $fontName;				// STRING Name of the font. For fonts
								// starting as Type 1, this is the
								// PostScript FullName. For fonts
								// starting in sfnt formats such as
								// TrueType and OpenType, this
								// is name ID 4, platform ID 1,
								// language ID 0 (Full name, Mac
								// OS, English).
	var $fontCopyright;			// STRING Arbitrary string

	function MKFontName ($tagData = "", $fontID = 1, $fontName = "", $fontCopyright = ""){

		$this->tagData = $tagData;

		if(strlen($tagData)){
			$this->get_fontName_data();
			return;
		}

		$this->fontID = $fontID;
		$this->fontName = $fontName;
		$this->fontCopyRight = $fontCopyright;
	}

	function set_fontID($fontID) { $this->fontID = $fontID; }
	function get_fontID() { return $this->fontID; }

	function set_fontName($fontName) { $this->fontName = $fontName; }
	function get_fontName() { return $this->fontName; }

	function set_fontCopyright($fontCopyright) { $this->fontCopyright = $fontCopyright; }
	function get_fontCopyright() { return $this->fontCopyright; }

	//
	function set_fontName_data($fnd = array()){

		if(count($fnd)) $this->get_fontName_data($fnd);
		else $fnd = $this->fetch_assoc();

		$this->tagData = write_fontName_data($fnd);

		return $this->tagData;
	}

	//
	function get_fontName_data($fnd = array()){

		if(!count($fnd)) $fnd = read_fontName_data($this->tagData);

		$this->fontID = $fnd["fontID"];
		$this->fontName = $fnd["name"];
		$this->fontCopyright = $fnd["copyright"];
	}

	//
	function fetch_assoc(){

		$fnd = array();
		$fnd["fontID"] = $this->fontID;
		$fnd["name"] = $this->fontName;
		$fnd["copyright"] = $this->fontCopyright;

		return $fnd;
	}

	//
	function fetch_xml($includeHeader = true, $tabLevel = 0, $nodeName = "fontName"){

		$xmlStr = $includeHeader ? XML_HEADER : "";

		$pfx = get_xml_indent_row(++$tabLevel);
		$xmlStr .= $pfx ."<" .$nodeName ." ";

		$xmlStr .= "fontID=\"" .$this->fontID ."\" ";
		$xmlStr .= "name=\"" . $this->fontName ."\" ";
		$xmlStr .= "copyright=\"" .$this->fontCopyright ."\" />";

		return $xmlStr;
	}
}



//------- end of mk classes - text -------------------

?>
